<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *学生列表
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';

$tabs=array(
	array('op'=>'list','title'=>'问卷调查'),
);
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['psize']?:10;
	$list=pdo_getslice('jy_wenjstar_log',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	//页面显示设置
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'[温馨提示]：
		</br>1、这里显示调查资料！
		','del_message'=>'确认删除该调查吗？','total'=>$total,'psize'=>$psize,'edit'=>false,'del_op'=>'del','html_to'=>'list_html','list'=>array(
			array('name'=>'member','title'=>'客户信息','type'=>'member'),
			array('name'=>'datiid','title'=>'所属问卷','type'=>'select','options'=>'lists'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'createtime','title'=>'日期','type'=>'time'),
		),'action'=>array(
			array('type'=>'href','op'=>'look','title'=>'浏览答卷'),
		),'batch'=>$batch),
		'search'=>array(
			array('type'=>'string','width'=>'15','title'=>'客户姓名','name'=>'title','help'=>''),
			array('name'=>'status','width'=>'15','title'=>'状态','type'=>'radio','options'=>'status'),
		),
	);
	$return['lists']=$this->getall('list',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['status']=$this->member_status;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='look'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_wenjstar_log',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		exi('请选择答卷','error');
	}
	$item['diyformfields']=$item['diyformfields']?json_decode($item['diyformfields'],true):array();
	foreach($item['diyformfields'] as &$v){
			if($v['type']==5 && $v['data']){
				$v['data'] = explode(";", $v['data']);
				foreach($v['data'] as $k=>&$i){
					if(empty($v['data'][$k])){
						unset($v['data'][$k]);
					}
				}
			}
	}
	$item['content']=$item['content']?json_decode($item['content'],true):array();
	foreach($item['content'] as &$v){
			$xuanxiang=$v['xuanxiang'];
			if($v['type']==4){
				$value=$v['data'];
				$v['data']='';
				foreach($xuanxiang as $k=>$xv){
					if($k==$value){
						$v['data']=$xv['title'];
						if($xv['needtian']){
							$v['data'] .=':'.$v['tian'][$k];
						}
					}
				}
			}
			if($v['type']==5){
				$v['data'] = explode(";", $v['data']);
				$value=$v['data'];
				$v['data']='';
				foreach($xuanxiang as $k=>$xv){
					if(in_array($k,$value)){
						$v['data'] .=$xv['title'].';';
						if($xv['needtian']){
							$v['data'] .=':'.$v['tian'][$k];
						}
					}
				}
			}
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'look',
		'desc'=>'客户信息',
		'look'=>array(
		)
	);
	$htmls['look'][]=array(
						'title'=>'客户信息',
						'type'=>'array',
						'name'=>'diyformfields',
						'list'=>array(
							array('type'=>'string','name'=>'title','title'=>'标题'),	
							array('type'=>'labelarray','name'=>'data','title'=>'内容'),	
						),
	);
	$htmls['look'][]=array(
						'title'=>'答卷内容',
						'type'=>'array',
						'name'=>'content',
						'list'=>array(
							array('type'=>'string','name'=>'title','title'=>'标题'),	
							array('type'=>'string','name'=>'data','title'=>'内容'),	
						),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_wenjstar_log',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}